package com.chenglu.android.mine.coupon;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.chenglu.android.ComnonPagerAdapter;
import com.chenglu.android.R;
import com.chenglu.android.TabEntity;
import com.chenglu.android.common.base.BaseActionBarActivity;
import com.chenglu.android.common.widget.NotScrollViewPager;
import com.chenglu.android.mine.coupon.fragment.CouponWSYFragment;
import com.chenglu.android.mine.coupon.fragment.CouponYSXFragment;
import com.chenglu.android.mine.coupon.fragment.CouponYSYFragment;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;


import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * @author: lyj
 * @Created: by Copyright 2023/3/24 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：我的优惠券
 */
public class CouponActivity extends BaseActionBarActivity {

    @BindView(R.id.ct_coupon)
    CommonTabLayout ctCoupon;
    @BindView(R.id.vp_coupon)
    NotScrollViewPager vpCoupon;

    private String[] titles = {"待使用", "已使用", "已失效"};
    private int[] iconUnselectIds = {R.drawable.seller_icon, R.drawable.seller_icon, R.drawable.seller_icon};
    private int[] iconSelectIds = {R.drawable.seller_icon, R.drawable.seller_icon, R.drawable.seller_icon};
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private ArrayList<CustomTabEntity> tabEntities = new ArrayList<>();
    ComnonPagerAdapter comnonPagerAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_coupon;
    }

    @Override
    protected void initView() {
        setCenterText("卡卷列表");

        fragments.add(CouponWSYFragment.getInstance(this,0));
        fragments.add(CouponYSYFragment.getInstance(this, 1));
        fragments.add(CouponYSXFragment.getInstance(this, 2));
        for (int i = 0; i < titles.length; i++) {
            tabEntities.add(new TabEntity(titles[i], iconSelectIds[i], iconUnselectIds[i]));
        }
        ctCoupon.setTabData(tabEntities);
        comnonPagerAdapter = new ComnonPagerAdapter(getSupportFragmentManager(), fragments);
        vpCoupon.setAdapter(comnonPagerAdapter);
        vpCoupon.setOffscreenPageLimit(0);
        ctCoupon.setCurrentTab(0);
        vpCoupon.setCurrentItem(0, false);
        ctCoupon.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                vpCoupon.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        vpCoupon.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                
            }

            @Override
            public void onPageSelected(int position) {
                      ctCoupon.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }


}
